﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KPIS.DBM;
using KPIS.GERP.SERVICE.DAL;
using KPIS.GERP.SERVICE.Model;
using System.Configuration;
using System.Data;

namespace KPIS.GERP.SERVICE.DAL
{
    public class Rule
    {
        Common common = new Common();
        Employee employee = new Employee();
        Absence absence = new Absence();
        DBManager dbManager = new DBManager(DataProvider.MySQL, "server=localhost;user id=root;pwd=root123456789;database=gerp;port=3307");

        public List<rule_absence> GetRuleAbsence(string rule_seq, string emp_type_seq, string absence_type_seq)
        {
            DataTable dtb;
            List<rule_absence> list = new List<rule_absence>();
            try
            {
                dbManager.Open();
                dbManager.CreateParameters(4);
                dbManager.AddParameters(0, "@delete_status", Common.DeletedStatus);
                dbManager.AddParameters(1, "@rule_absence_seq", rule_seq);
                dbManager.AddParameters(2, "@emp_type_seq", emp_type_seq);
                dbManager.AddParameters(3, "@absence_type_seq", absence_type_seq);

                string strSQL = "select * from rule_absence where record_status <> @delete_status"
                    + (!string.IsNullOrWhiteSpace(rule_seq) ? " and rule_absence_seq = @rule_seq" : "")
                    + (!string.IsNullOrWhiteSpace(emp_type_seq) ? " and emp_type_seq = @emp_type_seq" : "")
                    + (!string.IsNullOrWhiteSpace(absence_type_seq) ? " and absence_type_seq = @absence_type_seq" : "")
                    ;

                dtb = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0];
                list = (List<rule_absence>)CollectionHelper.ConvertTo<rule_absence>(dtb);

            }
            catch (Exception ex)
            {
                throw new NotImplementedException();
            }
            finally
            {
                {  dbManager.Connection.Close(); dbManager.Dispose();  }
            }
            return list;
        }
    }
}
